<?php
class GoodsTag{
	public $tag=array(
		"channel"=>array("block"=>1,"level"=>4)
		);
	// 自定义栏目标签
	public function _channel($arr,$content){
		$cid=$arr['cid'];
		// p($cid);
		
		$php=<<<str
		<?php
		\$cid=explode(',','$cid');
		\$result=M("category")->where(array("cid"=>\$cid))->all();
		foreach(\$result as \$field):
			\$field['url']=U("category",array("cid"=>\$field['cid']));
		?>
str;
		$php.=$content;
		$php.="<?php endforeach?>";
		return $php;
	}

	// 自定义商品标签
	public function _goods($arr,$content){
			$row=$arr['row'];
			$cid=$arr['cid'];
			$php=<<<str
			<?php
			\$cid=explode(",",str_replace(' ','', '$cid'));
			\$Model=M("goods");
			\$result=\$Model->order("rand()")->limit($row)->where(array("cid"=>\$cid))->all();
			foreach(\$result as \$field):
				\$field['url']=U('content',array("gid"=>\$field['gid']));
				\$field['index_pic']="__ROOT__/".\$field['index_pic'];
			
			?>
str;
	   	$php.=$content;
	   	$php.="<?php endforeach ?>";
	   	return $php;
	}
}